package com.ruoyi.quartz.task;

import com.ruoyi.common.integrate.constant.SendTemplate;
import com.ruoyi.common.integrate.domain.User;
import com.ruoyi.common.integrate.service.QYWeiXinService;
import com.ruoyi.quartz.service.IWorkJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }

    @Autowired
    private QYWeiXinService qyWeiXinService;

    @Autowired
    private IWorkJobService workJobService;

    /**
     * 定时 预警工时填报
     */
    public void ryWarningFillByWork() {
        System.out.println("定时预警工时填报");
        logger.info("预警_提醒未填报人员");
        List<User> notFillUsers = workJobService.getNotFillUsers();
        String notFillUsersStr = notFillUsers.stream().map(User::getUserid).collect(Collectors.joining("|"));
        String notFillContent = String.format(SendTemplate.FILL_MESSAGE_SEND, SendTemplate.NOT_FILL);
        qyWeiXinService.wxSend(notFillUsersStr, notFillContent);
    }

    /**
     * 定时 预警工时回退、未审核
     */
    public void ryWarningByWork() {
        logger.info("预警_提醒回退人员");
        List<User> isBackUsers = workJobService.getIsBackUsers();
        String isBackUsersStr = isBackUsers.stream().map(User::getUserid).collect(Collectors.joining("|"));
        String isBackContent = String.format(SendTemplate.FILL_MESSAGE_SEND, SendTemplate.IS_BACK);
        qyWeiXinService.wxSend(isBackUsersStr, isBackContent);

        logger.info("预警_提醒未审核人员");
        List<User> notCheckUsers = workJobService.getNotCheckUsers();
        String notCheckUsersStr = notCheckUsers.stream().map(User::getUserid).collect(Collectors.joining("|"));
        String notCheckContent = String.format(SendTemplate.FILL_MESSAGE_SEND, SendTemplate.NOT_CHECK);
        qyWeiXinService.wxSend(notCheckUsersStr, notCheckContent);
    }
}
